layui.use(['form','layer'], () =>(function ({form,layer,url,contentType,ok}) {

    if (window != top){
        top.location.href = location.href;
    }
    if (type==2){
        layer.alert("您已被迫下线")
    }
    form.render(),
    //点击 图片 验证码 刷新函数
    $("#img-code").click(function (event) {
        $(this).attr("src","/security/login/captcha?"+Math.random()*100)
        event.stopPropagation();
    }),

    form.on('submit(login)',({field})=>{
        $.ajax({
            type:'post',
            url:url,
            data:field,
            success:(data) => (
                console.log("login-data",data),
                data.code=="200" && data.isok? (
                    console.log("login-data",data),
                    window.location.href=data.data
                ):layer.msg(data.msg,{icon:7})
            )
        })
        return false;
    })

})(
    {
        form: layui.form,
        layer: layui.layer,
        url: "/security/login",
        contentType: 'application/json;charset=utf-8',
        ok: function (msg, icon) {
            layui.layer.confirm(msg, {
                id: "ok",
                icon: icon,
                anim: 4,
                title: '提示',
                btn: ['确定'],
                closeBtn: false,
                success: function (layero) {
                    var btn = layero[0].getElementsByClassName('layui-layer-btn')[0].getElementsByTagName('A')[0];
                    btn.href = 'javascript:void(0)';
                    btn.focus();
                },
                yes: function (index, layero) {
                    layer.close(index); //再执行关闭
                },
                end: function () {

                }
            });
        },
    }
))



